package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Duty;
import cn.wolfcode.crm.query.DutyQueryObject;
import cn.wolfcode.crm.service.IDutyService;
import cn.wolfcode.crm.util.JsonResult;
import com.alibaba.fastjson.JSON;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("duty")
public class DutyController {

    @Autowired
    private IDutyService dutyService;

    @RequestMapping("view")
    @RequiresPermissions(value = {"potentialDuty:view","潜在客户页面"},logical = Logical.OR)
    public String view(){
        return "duty/duty";
    }

    @RequestMapping("selectAll")
    @ResponseBody
    public List<Duty> selectAll(){
        return dutyService.selectAll();
    }

    /**
     * 登记上班打卡时间的方法
     * @return
     */
    @RequestMapping("signOn")
    @ResponseBody
    public JsonResult saveOrUpdate() {
        JsonResult jsonResult = new JsonResult();
        try{
            dutyService.saveOrUpdate( new Duty());
        }catch (Exception e){
            jsonResult.mark(e.getMessage());
        }
        return jsonResult;
    }
    /**
     * 登记下班打卡时间的方法
     * @return
     */
    @RequestMapping("signOff")
    @ResponseBody
    public JsonResult signOff() {
        JsonResult jsonResult = new JsonResult();
        try{
            dutyService.signOff();
        }catch (Exception e){
            jsonResult.mark(e.getMessage());
        }
        return jsonResult;
    }


    @RequestMapping("list")
    @ResponseBody
    public Object list(DutyQueryObject qo) throws Exception{
        Object json = JSON.toJSON(dutyService.query(qo));
        return json;
    }

}
